package sbp.dao;

import org.hibernate.Session;

public class DAO<T> {
	
	@SuppressWarnings("rawtypes")
	private Class classePersistencia;
	private Session session;
	
	@SuppressWarnings("rawtypes")
	public DAO(Session session, Class classePersistencia) {
		this.session = session;
		this.classePersistencia = classePersistencia;
	}
	
	@SuppressWarnings("unchecked")
	public T carregar (Integer codigo) {
		return (T) session.load(classePersistencia, codigo);
	}
	
	public void salvar(T t) {
		this.session.save(t);
	}
	
	public void atualizar(T t){
		this.session.update(t);
	}
	
	public void excluir(T t) {
		this.session.delete(t);
	}
	
}
